﻿using System;

namespace XchangeStreamer.Subscriber.SDK
{
    internal sealed class Processor<T, K> : IProcessor
    {
        #region Private Fields

        private Action<K, int, TimeSpan> logicRunner;

        #endregion

        #region Const.

        private Processor()
        { }

        public Processor(Action<K, int, TimeSpan> logicRunner)
        {
            this.logicRunner = logicRunner;
        }

        #endregion


        #region IProcessor Members

        public void Run(XchangeStreamer.Core.Message message)
        {
            var info = XchangeStreamer.Utilities.Compression<T>.Decompress<K>(message.Content, message.IsCompressed);
            System.Threading.Tasks.Task.Factory.StartNew(() =>
            {
                this.logicRunner(info, message.MessageId, message.Time);
            });
        }

        #endregion
    }
}
